package com.ruoyi.web.controller.dangerControl;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.utils.pengjie.SnowflakeIdUtils;
import com.ruoyi.dangerControl.vo.HdInspectionStandardVo;
import com.ruoyi.system.input.SysDictInput;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dangerControl.domain.HdInspectionStandard;
import com.ruoyi.dangerControl.service.IHdInspectionStandardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 检查标准Controller
 *
 * @author lth
 * @date 2023-12-13
 */
@RestController
@RequestMapping("/dangerControl/standard")
public class HdInspectionStandardController extends BaseController
{
    @Autowired
    private IHdInspectionStandardService hdInspectionStandardService;

    /**
     * 查询检查标准列表
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:standard:list')")
    @GetMapping("/list")
    public TableDataInfo list(HdInspectionStandard hdInspectionStandard)
    {
        startPage();
        List<HdInspectionStandard> list = hdInspectionStandardService.selectHdInspectionStandardList(hdInspectionStandard);
        return getDataTable(list);
    }

    /**
     * 导出检查标准列表
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:standard:export')")
    @Log(title = "检查标准", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HdInspectionStandard hdInspectionStandard)
    {
        List<HdInspectionStandard> list = hdInspectionStandardService.selectHdInspectionStandardList(hdInspectionStandard);
        ExcelUtil<HdInspectionStandard> util = new ExcelUtil<HdInspectionStandard>(HdInspectionStandard.class);
        util.exportExcel(response, list, "检查标准数据");
    }

    /**
     * 获取检查标准详细信息
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:standard:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hdInspectionStandardService.selectHdInspectionStandardById(id));
    }

    /**
     * 新增检查标准
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:standard:add')")
    @Log(title = "检查标准", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HdInspectionStandard hdInspectionStandard)
    {
        long id = new SnowflakeIdUtils(5, 8).nextId();
        hdInspectionStandard.setId(id);
        hdInspectionStandard.setCode("HDIS-"+(id+1));
        return toAjax(hdInspectionStandardService.insertHdInspectionStandard(hdInspectionStandard));
    }

    /**
     * 修改检查标准
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:standard:edit')")
    @Log(title = "检查标准", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HdInspectionStandard hdInspectionStandard)
    {
        return toAjax(hdInspectionStandardService.updateHdInspectionStandard(hdInspectionStandard));
    }

    /**
     * 删除检查标准
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:standard:remove')")
    @Log(title = "检查标准", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hdInspectionStandardService.deleteHdInspectionStandardByIds(ids));
    }


    /**     条件查询
    * @Author lth
    * @Description //TODO
    * @Date 17:10 2023/12/13
    * @Param
    * @return
     **/
    @PreAuthorize("@ss.hasPermi('dangerControl:standard:query')")
    @GetMapping("/getInfoByCondition")
    public TableDataInfo getInfoByCondition(@RequestBody HdInspectionStandardVo vo){
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<HdInspectionStandard> list = hdInspectionStandardService.getInfoByCondition(vo);
        return getDataTable(list);

    }














}
